package com.summer.system.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.cors.CorsConfiguration;
import org.springframework.web.cors.UrlBasedCorsConfigurationSource;
import org.springframework.web.filter.CorsFilter;

@Configuration

public class CORSFilter {
    @Bean
    public CorsFilter corsFilter() {
        CorsConfiguration config = new CorsConfiguration();

        config.addAllowedOrigin("*");       //允许白名单域名进行跨域调用
        config.setAllowCredentials(true);   //允许跨越发送cookie
        config.addAllowedHeader("*");       //放行全部原始头信息
        config.addAllowedMethod("*");      //允许所有请求方法跨域调用
        UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
        source.registerCorsConfiguration("/**", config); // 拦截过滤所有请求
        return new CorsFilter(source);
    }

}
